<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
$this->addCssFile('/project/apps/ecga/styles/style.css');
$this->addCssFile('/project/apps/ecga/styles/datagrid.css');
$this->addCssFile('/project/apps/ecga/styles/product.css');
$this->addCssFile('/statics/js/facebox/css/facebox.css');
$this->addCssFile('/project/apps/ecga/styles/form.css');

$this->addScriptFile('/statics/js/tooltips/tooltips.js');
$this->addScriptFile('/statics/js/datagrid/datagrid.js');
$this->addScriptFile('/statics/js/facebox/facebox.js');
?>
<body>
    <?php $this->import('tips'); ?>
    <div class="action-header">
        <h3><?php $this->put('渠道列表');?></h3>
        <p class="action-desc"><?php $this->put('您可以在这里查看所有渠道，或者点击这里');?><a href="?a=add" rel="facebox" id="addSite" title="添加渠道"><?php $this->put('添加渠道');?></a>。</p>
    </div>
    <div class="datagrid">
        <div class="gridbar nobg ">
            <div class="gridbar-left">
                <div class="form">
                    <select id="batchOptions">
                        <option value=""><?php $this->put('批量操作');?></option>
                        <!-- <option value="batchRemove" class="confirm:'<?php $this->put('您确定要删除选中项目吗?');?>'"><?php $this->put('删除');?></option> -->
                    </select>
                    <input type="button" id="batchBtn" class="button" value="<?php $this->put('确定');?>"/>
                </div>
             </div>
            <div class="pagelist-box">
                <div class="pagelist-box">
                <?php $this->htmlPageLinks($list, $uri) ?>
                </div>
            </div>
        </div>
    <!-- 快速编辑模板 -->
    <table id="inlineEditTable" class="inline-edit-form" style="display:none;"></table>

        <div style=" margin:0 20px; ">
            <table id="datagrid" class="datagrid-table" style="width:100%" border="0" cellspacing="0" cellpadding="0">
                <tr class="lock-th">
                    <th class="first"><input type="checkbox"/></th>
                    <th><?php $this->put('中文名称');?></th>
                    <th><?php $this->put('英文名称');?></th>
                    <th><?php $this->put('地址');?></th>
                    <?php if (count($projects) >= 2 || $isBoss) : ?>
                    <th><?php $this->put('所属项目');?></th>
                    <?php endif; ?>
                    <th><?php $this->put('渠道分组');?></th>
                </tr>
        <?php if (!empty($list)): ;?>
            <?php foreach ($list as $item): 
            ?>
                <tr class="<?php $this->alternate();?>" recordid='<?php $this->put($item['id']);?>'>
                    <td class="first"><input type="checkbox" name="id[]" value="<?php $this->put($item['id']);?>"/></td>
                    <td>
                        <p class="title row-masterName"><?php $this->put($item['cname']);?></p>
                        <p class="actions hidden">
                            <span><a href="#" rel="facebox" title="编辑" id="editSite_<?php $this->put($item['id']);?>">编辑</a></span>
                        </p>
                    </td>
                    <td class="row-email"><?php $this->put($item['ename']);?></td>
                    <td class="row-email"><?php $this->put($item['siteUrl']);?></td>
                <?php if (count($projects) >= 2 || $isBoss) : ?>
                    <td class="row-email"><?php $this->put(!isset($projectName[$item['id']]) ? '' : $projectName[$item['id']])?></td>
                <?php endif; ?>
                    <td class="row-email"><?php $this->put($item['tag']);?></td>
                </tr>
            <?php endforeach; ?>
        <?php endif;?>
            </table>
            <?php $this->notFound($list) ?>
        </div>
        <div class="bottombar">
            <div class="gridbar-left">
                <span><?php $this->sprintf('共计 (%s) 条记录', $list->recordCount); ?></span>
                <span><?php $this->sprintf('显示 (%s - %s)', $list->start + 1, min($list->start + $list->pageSize , $list->recordCount)); ?></span>
            </div>
            <div class="pagelist-box">
                <?php $this->htmlPageLinks($list, $uri) ?>
            </div>
        </div>
    </div>
    <?php $this->import('footer'); ?>
<script type="text/javascript">
    window.addEvent('domready', function() {

        var dg = new DataGrid($("datagrid"), {
            "inlineEditTemplate": "inlineEditTable"
        });
        window.fb = new Facebox({showFooter: false, "width": "auto"});
        $$('a[id^=editSite_]').each(function(target, index){
            var tmp = target.id.split('_');
            target.href = '/sites.php?a=edit&id=' + tmp[1];
        });
        $$('a[id=addSite]').each(function(target, index){
            target.href = 'sites.php?a=add';
        });
       
    });
    function checkSiteForm(tag) {
        if (tag) {
            if ($('cname').value.trim() == '') {
                $('adviceMsg').innerHTML = '请输入中文名称';
                $('cname').focus();
                return false;
            }
            if ($('ename').value.trim() == '') {
                $('adviceMsg').innerHTML = '请输入英文地址';
                $('ename').focus();
                return false;
            }
            if ($('siteUrl').value.trim() == '') {
                $('adviceMsg').innerHTML = '请输入地址';
                $('siteUrl').focus();
                return false;
            }
            var jsonRequest = new Request.JSON({
                url: $('siteForm').action,
                onComplete: function(res) {
                    if (res.result){
                       $('adviceMsg').set('class', 'validation-cmpltn');
                       location.reload(true);
                    }
                    $('adviceMsg').innerHTML = res.message;
                }
            }).post($('siteForm'));
        } else {
            window.fb.close();
        }
    }
</script>
</body>
</html>
